package com.qxglxt.qxgl.model;


import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import lombok.Data;

@Data
@Entity
@Table
public class Modules {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;//模块编号
    private String name;//模块名称
    private Integer parentId;//父模块编号
    private String path;//模块路径
    private String weight;//权重
    private String reservstion;//预留字符串字段
    private String remark;//预留整数字段

    @JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(
			name = "roles_modules",
			joinColumns =  {@JoinColumn(name = "module_id") },
			inverseJoinColumns = {@JoinColumn(name="role_id")}
			)
	@NotFound(action = NotFoundAction.IGNORE)
	private Set<Roles> roles = new HashSet<Roles>();
}